import { Controller, Inject, Get, Query, Body, Post, Put, Param, Del } from '@midwayjs/core';
import { GenTableService } from "@service/tool/genTable.service";
import { ListGenTableDTO, CreateGenTableDTO, UpdateGenTableDTO } from "@dto/tool/genTable.dto";
import { Auth } from "@decorator/auth.decorator";
import { BusinessType, Log } from "@decorator/log.decorator";

@Controller('/tool/gen')
export class PostController {
  @Inject()
  genTableService: GenTableService;

  // 获取列表
  @Auth('tool:genTable:list')
  @Get('/list')
  async list(@Query() queryParams: ListGenTableDTO) {
    return await this.genTableService.list(queryParams);
  }

  // 新增
  @Auth('tool:genTable:add')
  @Log({ title: '代码生成', businessType: BusinessType.ADD })
  @Post('/')
  async create(@Body() genTable: CreateGenTableDTO) {
    return await this.genTableService.create(genTable);
  }

  // 删除
  @Auth('tool:genTable:remove')
  @Log({ title: '代码生成', businessType: BusinessType.REMOVE })
  @Del('/:tableId')
  async delete(@Param('tableId') tableId: string) {
    return await this.genTableService.delete(tableId);
  }

  // 修改
  @Auth('tool:genTable:edit')
  @Log({ title: '代码生成', businessType: BusinessType.EDIT })
  @Put('/')
  async update(@Body() genTable: UpdateGenTableDTO) {
    return await this.genTableService.update(genTable);
  }

  // 获取详情
  @Auth('tool:genTable:query')
  @Get('/:tableId')
  async get(@Param('tableId') tableId: number) {
    return await this.genTableService.detail(tableId);
  }
}
